import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2021/10/30
 * Time: 10:07
 * Description:
 */
public class TestDemo {


    public static void main(String[] args) throws UnsupportedEncodingException {

        String str = "高博";
        byte[] bytes = str.getBytes("UTF8");
        System.out.println(Arrays.toString(bytes));
    }

    public static boolean isNumber(String str) {
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if(ch<'0' || ch > '9') {
                return false;
            }
        }
        return true;
    }

    public static void main17(String[] args) {
        String str = "1a23456" ;
        System.out.println(isNumber(str));
    }

    public static void main16(String[] args) {
        char[] chs = {'a','b','c','d'};
        String str1 = new String(chs,1,3);
        System.out.println(str1);

        String str2 = "hello";

        char[] chars = str2.toCharArray();
        System.out.println(Arrays.toString(chars));


        /*char ch = str2.charAt(2);
        System.out.println(ch);*/


    }

    public static void main15(String[] args) throws NoSuchFieldException, IllegalAccessException {
        String str = new String("Hello");
        Class cl = String.class;
        Field field = cl.getDeclaredField("value");
        // 将这个字段的访问属性设为 true
        field.setAccessible(true);
        // 把 str 中的 value 属性获取到.
        char[] value = (char[]) field.get(str);
        // 修改 value 的值
        value[0] = 'h';
        System.out.println(str);
    }

    public static void main14(String[] args) {
        String str = "Hello";
        str = "h" + str.substring(1);
        System.out.println(str);
    }


    public static void main13(String[] args) {
        String str1 = "hello";
        str1= str1+ "world";
        System.out.println(str1);
    }


    public static void main12(String[] args) {
        String str2 = "11";
        String str1 = new String("1")
                +new String("1");
        str1.intern();
        System.out.println(str1 == str2);
    }

    public static void main11(String[] args) {
        String str1 = new String("1")
                +new String("1");
        str1.intern();
        String str2 = "11";
        System.out.println(str1 == str2);
    }

    public static void main10(String[] args) {
        String str1 = new String("Hello");
        str1=str1.intern();
        String str2 = "Hello";
        System.out.println(str1 == str2);
    }

    public static void main9(String[] args) {
        //String str = new String("Hello");
        String str = null;
// 方式一
        System.out.println(str.equals("Hello"));
// 方式二
       System.out.println("Hello".equals(str));
    }

    public static void main8(String[] args) {
        String str1 = "hello";
        String str2 = "he"+"llo";
        System.out.println(str1 == str2);
    }

    public static void main7(String[] args) {
        String str1 = "hello";
        String str2 = "he";
        String str3 = "llo";
        String str4 = str2+str3;
        System.out.println(str1 == str4);
    }

    public static void main6(String[] args) {
        String str1 = "hello";
        String str2 = new String("he")
                +new String("llo");
        System.out.println(str1 == str2);

    }

    public static void main5(String[] args) {
        String str1 = "hello";
        String str2 = "hello";
        System.out.println(str1 == str2);
    }


    public static void main4(String[] args) {
        String str1 = "hello";
        String str2 = "he"+new String("llo");
        System.out.println(str1 == str2);
        System.out.println(str1.equals(str2));
    }

    public static void func(String s,char[] ch) {
        s = "gaobo";
        ch[0] = 'p';
    }

    public static void main3(String[] args) {
        String str1 = "hello";
        char[] chars = {'b','i','t'};
        func(str1,chars);
        System.out.println(str1);
        System.out.println(Arrays.toString(chars));
    }

    public static void main2(String[] args) {
        String str1 = "hello";
        String str2 = new String("hello");
        System.out.println(str1 == str2);
        //System.out.println(str1.equals(str2));
    }



    public static void main1(String[] args) {
        String str1 = "hello";
        String str2 = new String("hello");
        char[] chs = {'a','b','c','d'};
        String str3 = new String(chs);
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
    }
}
